// 记录本
// state 仓库数据

import * as types from './actionTypes';

const defaultState = {
    inputValue: '123',
    list: []
};
export default (state = defaultState,action) => {
    if (action.type === types.HANDLE_CHANGE_VALUE) {
        const newInputValue = JSON.parse(JSON.stringify(state));
        newInputValue.inputValue = action.value;
        return newInputValue;
    }
    if (action.type === types.HANDLE_SUBMIT) {
        const newState = JSON.parse(JSON.stringify(state));
        newState.list.push(newState.inputValue);
        newState.inputValue = '';
        return newState;
    }
    if (action.type === types.HANDLE_DELETE_ITEM) {
        const newState = JSON.parse(JSON.stringify(state));
        newState.list.splice(action.index,1);
        return newState;
    }
    if (action.type === types.INIT_DATA) {
        const newState = JSON.parse(JSON.stringify(state));
        newState.list = action.data;
        return newState;
    }
    return state;
}